package zy.blogs.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import zy.blogs.entity.Order;
import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Results({
            @Result(column = "id",property="id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.zy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one =@One(select = "com.zy.mapper.ParkingLotMapper.selectById")),
            @Result(column = "vehicle_id",property = "vehicle",one =@One(select = "com.zy.mapper.PricingStandardMapper.selectById")),

    })
    @Select("select * from order join pricing_standard on "+
            "pricing_standard.id=parking_lot.pricing_standard_id"+
            "join parking_lot on order.parking_lot_id=parking_lot.id"+
            "join vehicle on order.vehicle_id=vehicle.id")
    List<Order> getAll();
    @Results({
            @Result(column = "id",property="id"),
            @Result(column = "pricing_standard_id",property = "pricingStandard",one =@One(select = "com.zy.mapper.PricingStandardMapper.selectById")),
            @Result(column = "parking_lot_id",property = "parkingLot",one =@One(select = "com.zy.mapper.ParkingLotMapper.selectById")),
            @Result(column = "vehicle_id",property = "vehicle",one =@One(select = "com.zy.mapper.VehicleMapper.selectById")),

    })
    @Select("select * from order join pricing_standard on "+
            "pricing_standard.id=parking_lot.pricing_standard_id"+
            "join parking_lot on order.parking_lot_id=parking_lot.id"+
            "join vehicle on order.vehicle_id=vehicle.id"+
            "where id=#{id}")
    Order getById(Long id);
    @Insert("select * from order join pricing_standard on "+
            "pricing_standard.id=parking_lot.pricing_standard_id"+
            "join parking_lot on order.parking_lot_id=parking_lot.id"+
            "join vehicle on order.vehicle_id=vehicle.id"+
            "where id=#{id}")


    int insert(Order entity);
    @Update("insert into order set in_dateTime=#{inDateTime},out_dateTime=#{outDateTime}"+
            ",price=#{price},is_pay_complete=#{isPayComplete},is_require_invoicing=#{isRequireInvoicing}"+
            ",parking_lot_id=#{parkingLot.id}"+
            ",pricing_standard_id=pricingStandard.id"+
            ",vehicle_id=vehicle.id"+
            "where id=#{id}")

    int update(Order entity);
}
